// Controllers 为控制器目录（MVC）

package Controllers

import (
	_ "fmt"
	"gin/study_1/Service"
	"github.com/gin-gonic/gin"
	"net/http"
	_ "strconv"
)

func TestInsert(c *gin.Context) {

	var testService Service.In_Stu_ser
	// 获得地址参数
	err := c.ShouldBindJSON(&testService)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "data": "错误"})
		return
	}

	id, err := testService.Insert()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    -1,
			"message": "Insert() error!",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    1,
		"message": "success",
		"data":    id,
	})

}

func GetAllStudent(c *gin.Context) {
	var testService Service.In_Stu_ser
	result := testService.SelectAllStudent()
	if len(result) != 0 {
		c.JSON(http.StatusOK, gin.H{
			"code":    1,
			"message": "成功",
			"data":    result,
		})
		return
	}

	c.JSON(http.StatusBadRequest, gin.H{
		"code":    -1,
		"message": "失败",
		"data":    "插入失败",
	})

}
